package cn.weekimwee.map3d

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.rxkotlin.addTo
import kotlinx.android.synthetic.main.activity_test_disposable.*
import java.util.concurrent.TimeUnit

class TestDisposableActivity : AppCompatActivity() {
    private var compositeDisposable:CompositeDisposable = CompositeDisposable()
    private lateinit var  disposable:Disposable
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test_disposable)
        Observable.timer(2,TimeUnit.SECONDS)
                .repeat()
                .subscribe({
                    Log.e("eeeee","----------------------------------------->>>>>>")
                },{

                },{

                },{
                    this.disposable = it
                })
                .addTo(compositeDisposable)

        disposeButton.setOnClickListener {
            disposable.dispose()
        }

        finishButton.setOnClickListener {
            finish()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.e("eeeee","compositeDisposable.size-->${compositeDisposable.size()}")
        compositeDisposable.dispose()
    }
}
